package view.Validator;

import javafx.scene.control.Control;
import javafx.scene.control.TextField;

import org.controlsfx.validation.ValidationResult;
import org.controlsfx.validation.Validator;

import enums.Message;


public class EMailValidator implements Validator<String>{
	@Override
	public ValidationResult apply(Control t, String u) {
		ValidationResult res = new ValidationResult();
		if(t instanceof TextField){
			String text = ((TextField) t).getText();
			if(!text.equals("")){
				if(!text.contains("@") || !text.contains(".")){
					res.addErrorIf(t, Message.INVALIDEMAIL.toString(), true);
				}				
			}
		}
		return res;
	}

}
